﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Perovich.GameObjects.Interfaces;
using Microsoft.Xna.Framework.Content;

namespace Perovich.GameObjects.Components
{
    public abstract class DrawableEntityComponent : EntityComponent, IDrawableExt, IHaveContent
    {
        bool visible = true;
        int drawOrder;

        #region IDrawableExt Members

        public virtual void DrawOnTargets(GameTime gameTime) {}

        public virtual void Draw(GameTime gameTime) { }

        public int DrawOrder
        {
            get
            {
                return drawOrder;
            }
            set
            {
                if (drawOrder != value)
                {
                    drawOrder = value;

                    OnDrawOrderChanged(EventArgs.Empty);
                }
            }
        }

        public event EventHandler<EventArgs> DrawOrderChanged;

        protected virtual void OnDrawOrderChanged(EventArgs e)
        {
            if (this.DrawOrderChanged != null)
            {
                this.DrawOrderChanged(this, e);
            }
        }

        public virtual bool Visible
        {
            get
            {
                return visible;
            }
            set
            {
                if (visible != value)
                {
                    visible = value;

                    OnVisibleChanged(EventArgs.Empty);
                }
            }
        }

        public event EventHandler<EventArgs> VisibleChanged;

        protected virtual void OnVisibleChanged(EventArgs e)
        {
            if (VisibleChanged != null)
            {
                VisibleChanged(this, e);
            }
        }

        #endregion

        #region IHaveContent Members

        public virtual void LoadContent()
        {
        }

        public virtual void UnloadContent()
        {
        }

        #endregion

        protected override void Dispose(bool disposing)
        {
            UnloadContent();
            base.Dispose(disposing);
        }
    }
}
